package set;

import java.util.TreeSet;

import org.junit.Test;

class Person implements Comparable<Person>{
	int age;
	
	public Person(int age) {
		super();
		this.age = age;
	}
	
	@Override
	public int compareTo(Person o) {
		return this.age - o.age;
	}

	@Override
	public String toString() {
		return "Person [age=" + age + "]";
	}
}

public class TreeSetDemo {
	@Test
	public void create() {
		TreeSet<Integer> set = new TreeSet<>();
		set.add(100);
		set.add(800);
		set.add(700);
		set.add(500);
		set.add(300);
		System.out.println(set);
		
		TreeSet<String> set2 = new TreeSet<>();
		set2.add("a");
		set2.add("z");
		set2.add("u");
		set2.add("o");
		set2.add("p");
		System.out.println(set2);
		
		TreeSet<Person> set3 = new TreeSet<>();
		set3.add(new Person(11));
		set3.add(new Person(20));
		set3.add(new Person(33));
		set3.add(new Person(55));
		set3.add(new Person(12));
		System.out.println(set3);
	}
}
